package com.sicnu.cheer.leaugebar.managemodule.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.sicnu.cheer.generalmodule.activity.BaseActivity;
import com.sicnu.cheer.generalmodule.adapter.base.CommonAdapter;
import com.sicnu.cheer.generalmodule.adapter.viewholder.CommonViewHolder;
import com.sicnu.cheer.generalmodule.bean.LeagueBean;
import com.sicnu.cheer.generalmodule.util.StringUtils;
import com.sicnu.cheer.leaugebar.managemodule.R;

import java.util.List;

public class LeagueDisplayActivity extends BaseActivity implements View.OnClickListener {
    private CommonAdapter<LeagueBean> mAdapter;
    private List<LeagueBean> list;
    private TextView title;
    private Intent intent;
    private GridView leagueGV;

    @Override
    public int getContentViewId() {
        return R.layout.activity_league_display;
    }

    @Override
    protected void initView() {
        super.initView();
        title = ((TextView) findViewById(R.id.title));
        findViewById(R.id.back).setOnClickListener(this);
        leagueGV = ((GridView) findViewById(R.id.league_gv));
    }

    @Override
    protected void initData() {
        super.initData();
        intent = getIntent();
    }

    @Override
    protected void afterViews() {
        super.afterViews();
        String titleStr = intent.getStringExtra("title");
        list= (List<LeagueBean>) intent.getSerializableExtra("list");
        if (!StringUtils.isEmpty(titleStr)){
            title.setText(titleStr);
        }
        leagueGV.setAdapter(mAdapter=new CommonAdapter<LeagueBean>(mThis,list,R.layout.item_league_display) {
            @Override
            public void convert(CommonViewHolder helper, LeagueBean item) {
                helper.setImageByUrl(R.id.item_league_logo_iv,item.getLogo());
                helper.setText(R.id.league_name_tv,item.getName());
            }
        });
        leagueGV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=new Intent();
                intent.putExtra("bean",list.get(position));
                setResult(2,intent);
                finish();
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.back){
            onBackPressed();
        }
    }
}
